using ViScript.Core.Blocks;
using ViScript.Core.Exceptions;
using ViScript.Core.Utils;

namespace ViScript.Core.Blocks
{
    public class RootBlock : NestedBlock
    {
        private readonly IEscapeStrategy escapeStrategy;

        public RootBlock(IEscapeStrategy escapeStrategy) : base(null)
        {
            this.escapeStrategy = escapeStrategy;
            AppendBlock(new NormalBlock());
        }

        public override void Append(char c)
        {
            if (CurrentBlock.ShouldAppendQuotedBlock(c))
            {
                AppendBlock(new QuotedBlock(escapeStrategy, c, this));
            }
            else
            {
                CurrentBlock.Append(c);
            }
        }

        public override bool ShouldAppendQuotedBlock(char c)
        {
            throw new ViScriptSystemException();
        }
    }
}